package model.service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.json.simple.JSONObject;

import model.dao.TestDAO;
import model.vo.PagingBean;

public class TestServiceImpl  implements TestService{
	PagingBean pb;
	TestDAO testDAO;
	public void setTestDAO(TestDAO testDAO) {
		this.testDAO=testDAO;
	}
	
	public JSONObject makepaging(int nowPage,String detail)throws SQLException{
		int max=0;
		if(detail.equals("par")){
		max=testDAO.maxProduct();
		}else if(detail.equals("dept")){
		max=testDAO.maxProductdept();	
		}else if(detail.equals("com")){
			
			max=testDAO.maxProductcom();
			
		}
		pb = new PagingBean(max,nowPage);
		JSONObject obj = new JSONObject();
		int totalgroup=pb.getTotalPageGroup();
		int nowpagegroup=pb.getNowPageGroup();
		int startpageofpagegroup=pb.getStartPageOfPageGroup();
		int endpageofpagegroup=pb.getEndPageOfPageGroup();
		boolean isnextpagegroup=pb.isNextPageGroup();
		boolean ispreviouspagegroup=pb.isPreviousPageGroup();
		
		obj.put("nowPage",nowPage);
		obj.put("totalgroup",totalgroup);
		obj.put("nowpagegroup", nowpagegroup);
		obj.put("startpageofpagegroup", startpageofpagegroup);
		obj.put("endpageofpagegroup", endpageofpagegroup);
		obj.put("isnextpagegroup", isnextpagegroup);
		obj.put("ispreviouspagegroup",ispreviouspagegroup);
		if(detail.equals("par")){
		obj.put("detail", "par");
		}else if(detail.equals("dept")){
		obj.put("detail", "dept");
		}else if(detail.equals("com")){
	
		obj.put("detail", "com");
		}
		return obj;
	}
	public List waitpar(int page) throws SQLException {
		
		return testDAO.waitpar(page);	
	}
	public void appcon(ArrayList list) throws SQLException {
		for(int i=0;i<list.size();i++){
			System.out.println("service:"+list.get(i));
			testDAO.appcon(list.get(i).toString());
		}
		
	}
	@Override
	public List waitdept(int page) throws SQLException {
		return testDAO.waitdept(page);	
		
	}
	

	public void appdept(ArrayList list) throws SQLException {
		for(int i=0;i<list.size();i++){
			testDAO.appdept(list.get(i).toString());
		}
	}
	@Override
	public List completepar(int page) throws SQLException {
		
		return testDAO.completepar(page);
	}
	
	public void compar(ArrayList list) throws SQLException {
		for(int i=0;i<list.size();i++){
			testDAO.compar(list.get(i).toString());
		}
	}
}
	
	

